﻿<Window x:Class="Profit.Views.MainView"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        mc:Ignorable="d"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
        xmlns:local="clr-namespace:Profit.Controls" 
        xmlns:Resources="clr-namespace:Profit.Resources" xmlns:Services="clr-namespace:Profit.Services" d:DesignHeight="316"
        d:DesignWidth="629"
        SizeToContent="Manual"
        WindowState="{Binding MainViewWindowState, Source={x:Static Services:RegistryUserSettings.Default}, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
        MinWidth="500"
        MinHeight="300"
        Width="{Binding Source={x:Static Services:RegistryUserSettings.Default}, Path=MainViewWidth, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
        Height="{Binding Source={x:Static Services:RegistryUserSettings.Default}, Path=MainViewHeight, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
        UseLayoutRounding="True"
        Icon="/Profit;component/Resources/Icons/app_32.ico">
    <Window.Resources>
        <Style x:Key="StatusBarItemAgentStyle" TargetType="{x:Type StatusBarItem}">
            <Setter Property="Content">
                <Setter.Value>
                    <StackPanel Orientation="Horizontal">
                        <Image UseLayoutRounding="False" Visibility="{Binding SelectedAgent.HasImageSource, Converter={StaticResource BooleanToVisibilityConverter}}" Source="{Binding SelectedAgent.ImageSource, Converter={StaticResource AgentImageSourceConverter}}" Margin="1" MaxWidth="24" MaxHeight="24" VerticalAlignment="Center">
                            <Image.CacheMode>
                                <BitmapCache RenderAtScale="1" EnableClearType="False" SnapsToDevicePixels="True" />
                            </Image.CacheMode>
                        </Image>
                        <TextBlock Margin="5,0,0,0" Text="{Binding SelectedAgent.Name}" VerticalAlignment="Center" HorizontalAlignment="Left"/>
                    </StackPanel>
                </Setter.Value>
            </Setter>
            <Setter Property="ToolTip">
                <Setter.Value>
                    <ToolTip Content="{x:Static Resources:Messages.label_current_agent}" />
                </Setter.Value>
            </Setter>
            <Style.Triggers>
                <DataTrigger Binding="{Binding SelectedAgent}" Value="{x:Null}">
                    <Setter Property="Content" Value="{x:Static Resources:Messages.label_select_agent}" />
                </DataTrigger>
            </Style.Triggers>
        </Style>
        <Style x:Key="StatusBarItemFittingStyle" TargetType="{x:Type StatusBarItem}">
            <Setter Property="Content" Value="{Binding SelectedFitting.Name}"/>
            <Setter Property="ToolTip">
                <Setter.Value>
                    <ToolTip Content="{x:Static Resources:Messages.label_current_fitting}"/>
                </Setter.Value>
            </Setter>
        </Style>
    </Window.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="1*" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        
        <Menu Grid.Row="0" Grid.ColumnSpan="2" >
            <MenuItem Header="{x:Static Resources:Messages.menu_file}" >
                <MenuItem Header="{x:Static Resources:Messages.menu_exit}" Command="{Binding ExitCommand}" />
            </MenuItem>
            <MenuItem Header="{x:Static Resources:Messages.menu_tools}">
                <MenuItem Header="{x:Static Resources:Messages.menu_settings}" Command="{Binding SettingsCommand}" />
            </MenuItem>
            <MenuItem Header="{x:Static Resources:Messages.menu_help}">
                <MenuItem Header="{x:Static Resources:Messages.menu_about}" Command="{Binding AboutCommand}" />
            </MenuItem>
        </Menu>
        
        <ToolBarTray Grid.Row="1" Grid.ColumnSpan="2" UseLayoutRounding="True" Background="{StaticResource WindowBackgroundBrush}">
            <ToolBar Band="0" BandIndex="0" Background="{StaticResource WindowBackgroundBrush}">
                <local:DropDownButtonControl ButtonCommand="{Binding ShowAgentDetailsCommand}" ButtonCommandParameter="{Binding SelectedAgent}" ButtonContent="{StaticResource AgentInfoImage}">
                    <local:DropDownButtonControl.ContextMenu>
                        <ContextMenu>
                            <MenuItem Header="{x:Static Resources:Messages.menu_new_agent}" Icon="{StaticResource AgentAddImage}" Command="{Binding NewAgentCommand}" />
                            <MenuItem Header="{x:Static Resources:Messages.menu_delete_agent}" Icon="{StaticResource AgentRemoveImage}" IsEnabled="{Binding HasSelectedAgent}" Command="{Binding DeleteAgentCommand}" CommandParameter="{Binding SelectedAgent}"  />
                            <MenuItem Header="{x:Static Resources:Messages.menu_agents}" ItemsSource="{Binding Agents}" >
                                <MenuItem.ItemContainerStyle>
                                    <Style TargetType="{x:Type MenuItem}" BasedOn="{StaticResource {x:Type MenuItem}}">
                                        <Setter Property="Command" Value="{Binding DataContext.SelectAgentCommand, RelativeSource={RelativeSource AncestorType=Window}}" />
                                        <Setter Property="CommandParameter" Value="{Binding}" />
                                    </Style>
                                </MenuItem.ItemContainerStyle>
                            </MenuItem>
                        </ContextMenu>
                    </local:DropDownButtonControl.ContextMenu>
                </local:DropDownButtonControl>
                <local:DropDownButtonControl IsEnabled="{Binding HasSelectedAgent}" ButtonContent="{StaticResource FittingImage}" ButtonCommand="{Binding FittingsListCommand}">
                    <local:DropDownButtonControl.ContextMenu>
                        <ContextMenu>
                            <MenuItem Header="{x:Static Resources:Messages.menu_save_fitting}" Command="{Binding SaveFittingCommand}" CommandParameter="{Binding SelectedFitting}" Icon="{StaticResource FittingSaveImage}" IsEnabled="{Binding IsFittingDirty}" />
                            <MenuItem Header="{x:Static Resources:Messages.menu_rename_fitting}" Command="{Binding RenameFittingCommand}" CommandParameter="{Binding SelectedFitting}" Icon="{StaticResource FittingInfoImage}" IsEnabled="{Binding HasSelectedFitting}"/>
                            <MenuItem Header="{x:Static Resources:Messages.menu_delete_fitting}" Command="{Binding DeleteFittingCommand}" CommandParameter="{Binding SelectedFitting}" Icon="{StaticResource FittingRemoveImage}" IsEnabled="{Binding HasSelectedFitting}"/>
                            <MenuItem Header="{x:Static Resources:Messages.menu_fittings}" ItemsSource="{Binding Fittings, IsAsync=True}">
                                <MenuItem.ItemContainerStyle>
                                    <Style TargetType="{x:Type MenuItem}" BasedOn="{StaticResource {x:Type MenuItem}}">
                                        <Setter Property="Command" Value="{Binding DataContext.SelectFittingCommand, RelativeSource={RelativeSource AncestorType=Window}}" />
                                        <Setter Property="CommandParameter" Value="{Binding}" />
                                    </Style>
                                </MenuItem.ItemContainerStyle>
                            </MenuItem>
                        </ContextMenu>
                    </local:DropDownButtonControl.ContextMenu>
                </local:DropDownButtonControl>
            </ToolBar>
            <ToolBar Band="0" BandIndex="0" Background="{StaticResource WindowBackgroundBrush}" >
                <local:DropDownButtonControl 
                    x:Name="btnExportFitting" 
                    ShowDropDownIcon="False"
                    ToolTip="{x:Static Resources:Messages.label_export_fitting}"
                    IsEnabled="{Binding HasSelectedFitting}"
                    ButtonCommand="{Binding ExportFittingCommand}" 
                    ButtonCommandParameter="{Binding SelectedFitting}" 
                    ButtonContent="{StaticResource FittingExport}" />
            </ToolBar>
        </ToolBarTray>

        <Grid Grid.Row="2" >
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="{Binding ItemsListColumnWidth,Source={x:Static Services:RegistryUserSettings.Default}, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"  />
                <ColumnDefinition Width="{Binding FittingControlColumnWidth, Source={x:Static Services:RegistryUserSettings.Default}, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
            </Grid.ColumnDefinitions>
            
            <local:ItemsListControl x:Name="itemsListControl" 
                                    Grid.Column="0"
                                    Margin="0,0,5,0"
                                    BorderBrush="{x:Null}"
                                    BorderThickness="0"
                                    AddModuleCommand="{Binding AddModuleCommand}"
                                    NewFittingCommand="{Binding NewFittingCommand}"/>

            <GridSplitter Grid.Column="0" Width="2" />
            
            <local:RobotControl x:Name="robotControl" 
                                Grid.Column="1"
                                Margin="0"
                                AllowDrop="True"
                                Robot="{Binding SelectedRobot}" 
                                AddModuleCommand="{Binding AddModuleCommand}"
                                RemoveModuleCommand="{Binding RemoveModuleCommand}"  />
        </Grid>

        <StatusBar Grid.ColumnSpan="2" Grid.Row="3" Background="White">
            <StatusBarItem Style="{StaticResource StatusBarItemAgentStyle}" />
            <Separator Background="{StaticResource LightGrayBrushKey}" />
            <StatusBarItem Style="{StaticResource StatusBarItemFittingStyle}"  />
            <Separator Background="{StaticResource LightGrayBrushKey}" />
            <StatusBarItem HorizontalContentAlignment="Right">
                <local:EventsViewerControl EventsSource="{Binding Events}" TraceEventTypeFilter="Warning"/>
            </StatusBarItem>
        </StatusBar>
    </Grid>
</Window>
